/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.user.controller.assembler;

import com.google.common.collect.Lists;
import net.siufung.core.utils.CopyUtil;
import net.siufung.market.base.user.mapper.entity.UserRole;
import net.siufung.market.base.user.controller.model.vo.UserRoleVo;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 *
 * 系统用户角色表 持久层展示层组装器
 *
 * @author 陈建峰
 * @since 2022-07-05 16:14:50
 */
public class UserRoleAssembler {

    /**
     * UserRole 转换成 UserRoleVo
     * @param userRole 数据库实体
     * @return UserRoleVo 视图
     */
    public static UserRoleVo from(UserRole userRole){
        if(!Objects.isNull(userRole)){
            UserRoleVo userRoleVo = new UserRoleVo();
            CopyUtil.copyProperties(userRole, userRoleVo);
            return userRoleVo;
        }
        return null;
    }

    /**
     * UserRoleList 转换成 UserRoleVoList
     * @param userRoleList 数据库实体集合
     * @return List<UserRoleVo> 视图集合
     */
    public static List<UserRoleVo> fromList(List<UserRole> userRoleList){
        List<UserRoleVo> userRoleVoList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(userRoleList)){
            UserRoleVo userRoleVo;
            for (UserRole userRole: userRoleList) {
                userRoleVo = new UserRoleVo();
                CopyUtil.copyProperties(userRole, userRoleVo);
                userRoleVoList.add(userRoleVo);
            }
        }
        return userRoleVoList;
    }
}

